import {
  requestUtil
} from "../../utils/requestUtil"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    swiperList: [],
    baseURL:"",
    indexCardList:[]
  },
  clickTab(event) {
    if(event.detail.title=='默认'){
      this.getIndexCard();
    }else if(event.detail.title== '最新发布'){
      this.getIndexCardsByCreate();
    }
    else if(event.detail.title== '收藏最多'){
      this.getIndexCardsByLikes();
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getSwiper();
    this.getIndexCard();
  },
  async getSwiper(){
    const result = await requestUtil({
      url: '/recipe/getSwiper',
      method: 'GET'
    });
    this.setData({
      swiperList: result.data,
    })
    
  },
  async getIndexCard(){
    const result = await requestUtil({
      url: '/recipe/getIndexCards',
      method: 'GET'
    });
    this.setData({
      indexCardList: result.data,
    })
  },
  async getIndexCardsByCreate(){
    const result = await requestUtil({
      url: '/recipe/getIndexCardsByCreate',
      method: 'GET'
    });
    this.setData({
      indexCardList: result.data,
    })
  },
  async getIndexCardsByCreate(){
    const result = await requestUtil({
      url: '/recipe/getIndexCardsByCreate',
      method: 'GET'
    });
    this.setData({
      indexCardList: result.data,
    })
  },
  async getIndexCardsByLikes(){
    const result = await requestUtil({
      url: '/recipe/getIndexCardsByLikes',
      method: 'GET'
    });
    this.setData({
      indexCardList: result.data,
    })
  },
  touchend(event){
    const id =event.currentTarget.id;
    // wx.navigateTo({
    //   url: './detail/detail?recipeId='+id,
    // })
  },
  jumpdetail(event){
    console.log(event);
    const id =event.currentTarget.id;
    wx.navigateTo({
      url: './detail/detail?recipeId='+id,
    })
  },
  // TODO: 页面刷新，重新加载数据
  
})